package com.memorywords.config;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
//import springfox.documentation.builders.ApiInfoBuilder;
//import springfox.documentation.builders.PathSelectors;
//import springfox.documentation.builders.RequestHandlerSelectors;
//import springfox.documentation.service.ApiInfo;
//import springfox.documentation.spi.DocumentationType;
//import springfox.documentation.spring.web.plugins.Docket;
//import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
//
//@Slf4j
//@Configuration
//@EnableSwagger2WebMvc
//public class Knife4jConfig {
//    /**
//     //     * 通过knife4j生成接口文档
//     //     * @return
//     //     */
////    @Bean
////    public Docket docket() {
////        log.info("生成文档");
////        ApiInfo apiInfo = new ApiInfoBuilder()
////                .title("背单词项目接口文档")
////                .version("1.0")
////                .description("背单词项目接口文档")
////                .build();
////        Docket docket = new Docket(DocumentationType.SWAGGER_2)
////                .apiInfo(apiInfo)
////                .select()
////                .apis(RequestHandlerSelectors.basePackage("com.memorywords.controller"))
////                .paths(PathSelectors.any())
////                .build();
////        return docket;
////    }
//    /**
//     * 创建 Docket 对象
//     */
//    @Bean
//    public Docket createRestApi() {
//        return new Docket(DocumentationType.SWAGGER_2)
//                .apiInfo(apiInfo())
//                .groupName("后台接口")          // 分组名称
//                .select()
//                // 扫描的包路径
//                .apis(RequestHandlerSelectors.basePackage("com.memorywords.controller"))
//                .paths(PathSelectors.any())
//                .build();
//    }
//
//    /**
//     * 文档基本信息
//     */
//    private ApiInfo apiInfo() {
//        return new ApiInfoBuilder()
//                .title("背单词项目接口文档")
//                .description("背单词项目接口文档")
//                .version("1.0.0")
//                .build();
//    }
//
//    /**
//     * 设置静态资源映射
//     */
//    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
//        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
//    }
//}
//


import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;

/**
 * Knife4j + OpenAPI 3 配置
 */
@Configuration
public class Knife4jConfig {

    /**
     * 文档基本信息
     */
    @Bean
    public OpenAPI openAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("背单词项目接口文档")
                        .description("背单词项目接口文档")
                        .version("1.0.0")
                        .contact(new Contact()
                                .name("qyq")
                                .email("dev@example.com")
                                .url("https://github.com/example"))
                        .license(new License()
                                .name("Apache 2.0")
                                .url("https://www.apache.org/licenses/LICENSE-2.0")));
    }

    /**
     * 默认分组（扫描全部）
     */
    @Bean
    public GroupedOpenApi defaultApi() {
        return GroupedOpenApi.builder()
                .group("default")
                .pathsToMatch("/**")
                .packagesToScan("com.memorywords.controller")
                .build();
    }
    /**
     //     * 设置静态资源映射
     //     */
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }



}
